package com.shuyu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shuyu.domain.Activity;
import com.shuyu.domain.ActivityCollectCard;
import com.shuyu.domain.ActivityProduct;
import com.shuyu.mapper.ActivityProductMapper;
import com.shuyu.service.ActivityCollectCardService;
import com.shuyu.service.ActivityProductService;
import com.shuyu.service.ActivityService;
import com.shuyu.vo.PointMailVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ActivityProductServiceImpl extends ServiceImpl<ActivityProductMapper, ActivityProduct> implements ActivityProductService {
    @Resource
    private ActivityService activityService;
    @Resource
    private ActivityCollectCardService activityCollectCardService;
    @Override
    public List<ActivityProduct> getProductListByActivityId(int activityId) {
        List<ActivityProduct> list = this.baseMapper.getProductListByActivityId(activityId);
        Activity activity = activityService.getById(activityId);
        if(activity == null){
            return list;
        }
        if(activity.getType()==1){//1：集卡消卡
            queryCollectCard(list);
        }
        return list;
    }

    @Override
    public List<PointMailVo> getPointMail() {
        return this.baseMapper.getPointMail();
    }

    private void queryCollectCard(List<ActivityProduct> list){
        for (ActivityProduct activityProduct : list) {
            List<ActivityCollectCard> activityCollectCardList = activityCollectCardService.getCollectCard(activityProduct.getId());
            activityProduct.setActivityCollectCardList(activityCollectCardList);
        }
    }
}
